package com.redteam.util;

import java.sql.Date;
import java.sql.Time;
import java.util.GregorianCalendar;

/**
 * Checks for conflicts between two reservation dates
 * @author Anthony Ferrari
 */
public class DateChecker {

    /**
     * Private so it can not be instanced.
     */
    private DateChecker() {
    }

    /**
     * Checks to see if the Second Time entered conflict with the first.
     * @param startDate
     * @param startTime
     * @param endDate
     * @param endTime
     * @param startDate2
     * @param startTime2
     * @param endDate2
     * @param endTime2
     * @return Returns true if there is a conflict
     */
    public static boolean checkForConflict(Date startDate, Time startTime, Date endDate, Time endTime, Date startDate2, Time startTime2, Date endDate2, Time endTime2) {
        boolean conflict = false;
        GregorianCalendar startingTime = new GregorianCalendar(startDate.getYear(), startDate.getMonth(), startDate.getDay(), startTime.getHours(), startTime.getMinutes(), startTime.getSeconds());
        GregorianCalendar endingTime = new GregorianCalendar(endDate.getYear(), endDate.getMonth(), endDate.getDay(), endTime.getHours(), endTime.getMinutes(), endTime.getSeconds());
        GregorianCalendar startingTime2 = new GregorianCalendar(startDate2.getYear(), startDate2.getMonth(), startDate2.getDay(), startTime2.getHours(), startTime2.getMinutes(), startTime2.getSeconds());
        GregorianCalendar endingTime2 = new GregorianCalendar(endDate2.getYear(), endDate2.getMonth(), endDate2.getDay(), endTime2.getHours(), endTime2.getMinutes(), endTime2.getSeconds());

        if (startingTime2.after(startingTime) && startingTime2.before(endingTime)) {
            conflict = true;
        } else if (endingTime2.after(startingTime) && endingTime2.before(endingTime)) {
            conflict = true;
        }
        return conflict;
    }
}
